home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / KILLFF.C < prev    next >
Text File  |  1993-04-05  |  3KB  |  112 lines

  1. .I 0 6
  2. /*
  3. ** KILLFF.C - A program was written to strip out all the Form Feeds
  4. ** in text files.
  5. **
  6. ** Public domain by Erik VanRiper, 12/22/91
  7. ** Modified by Bob Stout, 17 Feb 93
  8. .D 1 11
  9. .I 13 11
  10. ** characters! The default action is to create a duplicate without
  11. ** Form Feeds, then remove the original and rename the dupliicate,
  12. ** although an explicit output file name may be specified.
  13. **
  14. ** Form Feed characters are replaced with newline characters ('\n').
  15. ** Since ANSI mandates that fwrite() will translate newlines when
  16. ** a stream is opened in text (non-binary) mode, these will appear
  17. ** in the ouput file in a format appropriate to the implementation,
  18. ** e.g. CRLF pairs on PC's.
  19. **
  20. ** Usage: KILLFF filename [newname]
  21. .D 14 4
  22. .I 23 1
  23. #define BSIZ 32768U             /* max size of read/write buffer */
  24. .D 24 1
  25. .I 29 9
  26.         temp[80],               /* output file name              */
  27.         *buf;                   /* buffer we will use to write   */
  28. /*        *s;                     /* searching pointer             */
  29.    size_t bad,                  /* check to see if write ok      */
  30.           num;                  /* number of bytes read          */
  31.    int retval  = EXIT_SUCCESS,  /* return value                  */
  32.        tmpflag = 0;             /* non-zero if tmpnam() used     */
  33.  
  34.    printf("\nKILL FORM FEEDS by Erik VanRiper & Bob Stout\n\n");
  35. .D 30 8
  36. .I 40 4
  37.       puts("Usage: KILLFF input_file [output_file]");
  38.       puts("\nIf no output file is given, the input file will "
  39.            "be replaced.");
  40.       return retval;                         /* return to OS     */
  41. .D 41 2
  42. .I 46 6
  43.    else
  44.    {
  45.       tmpnam(temp);
  46.       tmpflag = -1;
  47.    }
  48.  
  49. .D 47 6
  50. .I 54 2
  51.       printf("\nCan't Open Input File %s",name);
  52.       return (retval = EXIT_FAILURE);        /* return to OS     */
  53. .D 55 3
  54. .I 60 1
  55.       printf("\nCan't Open Output File %s",temp);
  56. .D 61 1
  57. .I 62 11
  58.       return (retval = EXIT_FAILURE);        /* return to OS     */
  59.    }
  60.  
  61.    if((buf = malloc(BSIZ)) == NULL)     /* malloc a large buffer */
  62.    {
  63.       printf("\nOut of memory\n");
  64.       return (retval = EXIT_FAILURE);        /* return to OS     */
  65.    }
  66.  
  67.    printf("Input file: %s Output file: %s\n",
  68.       name,tmpflag ? name : temp);
  69. .D 63 5
  70. .I 70 9
  71.    while (0 < (num = fread(buf,sizeof(char),BSIZ,in)))
  72.    {
  73.       size_t i;
  74.  
  75.       for (i = 0; i < num; ++i)              /* look for FF      */
  76.          if ('\f' == buf[i])
  77.             buf[i] = '\n';                  /* change to newline */
  78.  
  79.       bad=fwrite(buf,sizeof(char),num,out);  /* write out buf    */
  80. .D 71 8
  81. .I 81 2
  82.          retval = EXIT_FAILURE;              /* return to OS     */
  83.          break;
  84. .D 82 4
  85. .D 87 1
  86. .I 91 10
  87.    if (tmpflag)
  88.    {
  89.       if (remove(name))
  90.       {
  91.          printf("Can't rename %s\n", name);
  92.          printf("Converted file is named %s\n", temp);
  93.       }
  94.       else
  95.          rename(temp, name);
  96.    }
  97. .I 92 13
  98.    return retval;                            /* return to OS     */
  99. }
  100. /*
  101.  
  102. List this source file to test this program!
  103.  
  104. New page
  105.  
  106. New page
  107.  
  108. All done
  109.  
  110. */
  111. .D 93 2
  112.